import * as transaction from './tx'
import expect from 'expect'

describe('Transaction', () => {
    it('Legacy 1', () => {
        expect(
            transaction.normalizeLegacyTransaction({
                action: {
                    __kind: 'Call',
                    value: '0x08716e418e68564c96b68192e985762740728018',
                },
                gasLimit: 489365n,
                gasPrice: 1000000000n,
                input: '0x7a93696a0000000000000000000000000000000000000000000000000000000000000000',
                nonce: 603n,
                signature: {
                    r: '0x934e9b41ca05ce6581f4ef6f3f1026b7d190e0e4d0ff63c9b91865beeeb52768',
                    s: '0x32314ac16b0234e643a46de09e39e62e32568b9dcbbd677fbff1e22ed649fa70',
                    v: 2606n,
                },
                value: 0n,
            })
        ).toEqual({
            to: '0x08716e418e68564c96b68192e985762740728018',
            gasLimit: 489365n,
            gasPrice: 1000000000n,
            input: '0x7a93696a0000000000000000000000000000000000000000000000000000000000000000',
            nonce: 603n,
            r: '0x934e9b41ca05ce6581f4ef6f3f1026b7d190e0e4d0ff63c9b91865beeeb52768',
            s: '0x32314ac16b0234e643a46de09e39e62e32568b9dcbbd677fbff1e22ed649fa70',
            v: 2606n,
            value: 0n,
            from: '0xbb9bf3b2207c51273959dc571e4e1f01fb3a0b8d',
            hash: '0x5c7f334c29086dd286b3e078c9bef3312bb6e460333514191560d0f7fc5068db',
            type: 0,
        })
    })

    it('Legacy 2', () => {
        expect(
            transaction.normalizeLegacyTransaction({
                action: {
                    __kind: 'Call',
                    value: '0x59c481548ce7ba13f3288df9f4fcf44a10a589a0',
                },
                gasLimit: 475986n,
                gasPrice: 1100000000n,
                input: '0xc093d5b4000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000140000000000000000000000000b654611f84a8dc429ba3cb4fda9fad236c505a1a0000000000000000000000000000000000000000000000000000000000000058000000000000000000000000000000000000000000000000000000000000000303b0ce3a3c09a347630b1f2803b77e8708cacbdb24f2f74961671eb476fbd57e000000000000000000000000f16d69efa7ae1e115b3655a2eaa26eabc5675708000000000000000000000000f16d69efa7ae1e115b3655a2eaa26eabc567570800000000000000000000000000000000000000000000000000000000000000012865b44f4bbd0cf5205f5a412e5dd879e3358d93825e83690f3005155235e0270000000000000000000000000000000000000000000000000000000061833e0d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004106015766ae80706c64fd42466a9e3ab893f7bb2f95d2b7067e8e5a24b1ac4dd44b8ac688c9e12b4a4fcdcf889a8472759dab2db5f01ccd2905595aa42af209f41b00000000000000000000000000000000000000000000000000000000000000',
                nonce: 5n,
                signature: {
                    r: '0x7e80a0c98760400defe1020a1b86c8b28d9b0cffb28c0f6b6488cd16009dd102',
                    s: '0x0aaf2d3cc7724d3acb78a3f4808cfcb9966a913baa4b5c777fe45959f9e5609d',
                    v: 27n,
                },
                value: 0n,
            })
        ).toEqual({
            to: '0x59c481548ce7ba13f3288df9f4fcf44a10a589a0',
            gasLimit: 475986n,
            gasPrice: 1100000000n,
            input: '0xc093d5b4000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000140000000000000000000000000b654611f84a8dc429ba3cb4fda9fad236c505a1a0000000000000000000000000000000000000000000000000000000000000058000000000000000000000000000000000000000000000000000000000000000303b0ce3a3c09a347630b1f2803b77e8708cacbdb24f2f74961671eb476fbd57e000000000000000000000000f16d69efa7ae1e115b3655a2eaa26eabc5675708000000000000000000000000f16d69efa7ae1e115b3655a2eaa26eabc567570800000000000000000000000000000000000000000000000000000000000000012865b44f4bbd0cf5205f5a412e5dd879e3358d93825e83690f3005155235e0270000000000000000000000000000000000000000000000000000000061833e0d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004106015766ae80706c64fd42466a9e3ab893f7bb2f95d2b7067e8e5a24b1ac4dd44b8ac688c9e12b4a4fcdcf889a8472759dab2db5f01ccd2905595aa42af209f41b00000000000000000000000000000000000000000000000000000000000000',
            nonce: 5n,
            r: '0x7e80a0c98760400defe1020a1b86c8b28d9b0cffb28c0f6b6488cd16009dd102',
            s: '0x0aaf2d3cc7724d3acb78a3f4808cfcb9966a913baa4b5c777fe45959f9e5609d',
            v: 27n,
            value: 0n,
            from: '0xf16d69efa7ae1e115b3655a2eaa26eabc5675708',
            hash: '0xefe449833f84122e5807dd4f40bfda7fe0c15ec5ff7de9707b857ed6150dc9b8',
            type: 0,
        })
    })

    it('EIP1559 1', () => {
        expect(
            transaction.normalizeEIP1559Transaction({
                accessList: [],
                action: {
                    __kind: 'Call',
                    value: '0x6a2d262d56735dba19dd70682b39f6be9a931d98',
                },
                chainId: 592n,
                gasLimit: 45037n,
                input: '0xa9059cbb000000000000000000000000acc4be41088e09cd68bb19d63ded3ae5385b406c000000000000000000000000000000000000000000000000000000000005a30b',
                maxFeePerGas: 9414057000n,
                maxPriorityFeePerGas: 8214057000n,
                nonce: 157n,
                oddYParity: false,
                r: '0x93e142dcfff8c1293f8123336f342c22ce833b816dccee9a6a420013741c01e5',
                s: '0x6aeefc932ed9045ce13db45ddfe6b0387f1c7213b38467ce8a9ffc76d3511839',
                value: 0n,
            })
        ).toEqual({
            to: '0x6a2d262d56735dba19dd70682b39f6be9a931d98',
            accessList: [],
            chainId: 592n,
            gasLimit: 45037n,
            input: '0xa9059cbb000000000000000000000000acc4be41088e09cd68bb19d63ded3ae5385b406c000000000000000000000000000000000000000000000000000000000005a30b',
            nonce: 157n,
            r: '0x93e142dcfff8c1293f8123336f342c22ce833b816dccee9a6a420013741c01e5',
            s: '0x6aeefc932ed9045ce13db45ddfe6b0387f1c7213b38467ce8a9ffc76d3511839',
            v: 0n,
            value: 0n,
            from: '0xa31d63ff5db5a6e238a7e73539dc95ed5cce2f45',
            hash: '0x54a4b229448782ae737cb57c7887ec19a5b0d7c3bc30c9f42cf6a15df96cb924',
            maxFeePerGas: 9414057000n,
            maxPriorityFeePerGas: 8214057000n,
            type: 2,
        })
    })

    it('EIP1559 2', () => {
        expect(
            transaction.normalizeEIP1559Transaction({
                accessList: [],
                action: {
                    __kind: 'Call',
                    value: '0x50b57b1cf97d0cc20690a14f263a8afc55cbee3d',
                },
                chainId: 1285n,
                gasLimit: 2000000n,
                input: '0x1a068b1300000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000317fb62cd298445266d1bdee42312266654ec9400000000000000000000000021d6dbca8aacdaa739e40180b1c8c828b46ae376000000000000000000000000e2293ba6fc806eb0903c4954218a436bec591bb5000000000000000000000000be2abe58edaae96b4303f194d2fad5233bad3d87',
                maxFeePerGas: 1030200000n,
                maxPriorityFeePerGas: 1030200000n,
                nonce: 188n,
                oddYParity: false,
                r: '0xe6d5ae3a46583455ab3e0373f2c24c961f7fdf45ab5ed4b4c896e77266ab559b',
                s: '0x2d25b6a8f721e2161bffc6339684be700675723447f1993d1eec67f6a1ab225a',
                value: 0n,
            })
        ).toEqual({
            to: '0x50b57b1cf97d0cc20690a14f263a8afc55cbee3d',
            accessList: [],
            chainId: 1285n,
            gasLimit: 2000000n,
            input: '0x1a068b1300000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000317fb62cd298445266d1bdee42312266654ec9400000000000000000000000021d6dbca8aacdaa739e40180b1c8c828b46ae376000000000000000000000000e2293ba6fc806eb0903c4954218a436bec591bb5000000000000000000000000be2abe58edaae96b4303f194d2fad5233bad3d87',
            nonce: 188n,
            r: '0xe6d5ae3a46583455ab3e0373f2c24c961f7fdf45ab5ed4b4c896e77266ab559b',
            s: '0x2d25b6a8f721e2161bffc6339684be700675723447f1993d1eec67f6a1ab225a',
            v: 0n,
            value: 0n,
            from: '0x4ec72cc0e9ae109e8828d0d0ca9e2969a0fe8a12',
            hash: '0xfd8084438f3593d38ce16dc2231b5528a5a7aa5f02f8a195f34753d6a63ee3c5',
            maxFeePerGas: 1030200000n,
            maxPriorityFeePerGas: 1030200000n,
            type: 2,
        })
    })

    it('EIP1559 3', () => {
        expect(
            transaction.normalizeEIP1559Transaction({
                accessList: [],
                action: {
                    __kind: 'Call',
                    value: '0x02a6dec99b2ca768d638fcd87a96f6069f91287c',
                },
                chainId: 1284n,
                gasLimit: 52370n,
                input: '0xa22cb465000000000000000000000000c7e929d05e52f62c3aa2bd180983fa2bf0abcc540000000000000000000000000000000000000000000000000000000000000001',
                maxFeePerGas: 100000000000n,
                maxPriorityFeePerGas: 100000000000n,
                nonce: 6n,
                oddYParity: true,
                r: '0xd9c6454dbdb8c759f43654998113ef96e5cef9d61665d90629bb81e6848dec4d',
                s: '0x2e6cff3357416152f6eed848109a71bb678e94f438215a6b00463fef5d450ca5',
                value: 0n,
            })
        ).toEqual({
            to: '0x02a6dec99b2ca768d638fcd87a96f6069f91287c',
            accessList: [],
            chainId: 1284n,
            gasLimit: 52370n,
            input: '0xa22cb465000000000000000000000000c7e929d05e52f62c3aa2bd180983fa2bf0abcc540000000000000000000000000000000000000000000000000000000000000001',
            nonce: 6n,
            r: '0xd9c6454dbdb8c759f43654998113ef96e5cef9d61665d90629bb81e6848dec4d',
            s: '0x2e6cff3357416152f6eed848109a71bb678e94f438215a6b00463fef5d450ca5',
            v: 1n,
            value: 0n,
            from: '0xf9ab72bde571f8e7bf7bdff210461c021f9f4425',
            hash: '0xe676a637226a011e7c3db5e1cde4caa75adace91e21bc8816e114be0a9ec2c4b',
            maxFeePerGas: 100000000000n,
            maxPriorityFeePerGas: 100000000000n,
            type: 2,
        })
    })
})
